//
//  ZLPullMenuContentCell.swift
//  ZLPullMenuSwift
//
//  Created by 科大 on 2025/1/16.
//

import UIKit

public class ZLPullMenuContentCell: UICollectionViewCell {
    // MARK: - Properties
    
    /// 数据
    public var option: ZLPullMenuOption? {
        didSet {
            updateUI()
        }
    }
    
    /// 标题
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.layer.borderWidth = 1
        label.layer.masksToBounds = true
        label.layer.cornerRadius = 3
        label.textAlignment = .center
        return label
    }()
    
    // MARK: - Initialization
    
    public override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - Private Methods
    
    private func updateUI() {
        guard let option = option else { return }
        
        titleLabel.text = option.optionTitle
        
        if option.selected {
            titleLabel.textColor = option.config.textSelectedColor
            titleLabel.font = option.config.selectedFont
            titleLabel.backgroundColor = option.config.backgroundSelectedColor
            titleLabel.layer.borderColor = option.config.borderSelectedColor.cgColor
        } else {
            titleLabel.textColor = option.config.textColor
            titleLabel.font = option.config.font
            titleLabel.backgroundColor = option.config.backgroundColor
            titleLabel.layer.borderColor = option.config.borderColor.cgColor
        }
    }
}
